package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import vo.Book;

public class bookDao {
	private Connection conn=null;
	public void initConnection()throws Exception{	
		
		String driverClass="com.mysql.jdbc.Driver";
	    String url="jdbc:mysql://localhost:3306/vote?useSSL=false&useUnicode=true&characterEncoding=UTF-8";
	    String user="root";
	    String password="womenilu2580";
	    Class.forName(driverClass);
	    conn=DriverManager.getConnection(url,user,password);	   
	}
	public HashMap getAllBook()throws Exception{
		HashMap hm=new HashMap();
		initConnection();
		Statement stat=conn.createStatement();
		String sql="SELECT BNO,BNAME,BPRICE FROM T_BOOK";
		ResultSet rs=stat.executeQuery(sql);
		while(rs.next())
		{
			Book book=new Book();
			book.setBookno(rs.getString("bno"));
			book.setBookname(rs.getString("bname"));
			book.setBookPrice(rs.getFloat("bprice"));
			hm.put(book.getBookno(), book);
		}
		conn.close();
		return hm;
	}
	
}
